package com.shangcheng.dubbo.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shangcheng.dubbo.mappers.PmsProductLadderMapper;
import com.shangcheng.model.domain.PmsProductLadder;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductLadderApiImpl implements PmsProductLadderApi {
    @Autowired
    private PmsProductLadderMapper productLadderMapper;

    @Override
    public void save(List<PmsProductLadder> productLadderList, Long id) {
        if (ObjectUtil.isNotEmpty(productLadderList)) {
            for (PmsProductLadder pmsProductLadder : productLadderList) {
                pmsProductLadder.setProductId(id);
                productLadderMapper.insert(pmsProductLadder);
            }
        }
    }

    @Override
    public List<PmsProductLadder> findByProductId(Integer id) {
        return productLadderMapper.selectList(new LambdaQueryWrapper<PmsProductLadder>().eq(PmsProductLadder::getProductId, id));
    }

    @Override
    public void updateById(List<PmsProductLadder> productLadderList) {
        for (PmsProductLadder pmsProductLadder : productLadderList) {
            productLadderMapper.updateById(pmsProductLadder);
        }
    }
}
